#!/usr/bin/python
# -*- coding: gbk -*-
import os
import py_compile

def walk_dir(dirpath, topdown=True):
    for root, dirs, files in os.walk(dirpath, topdown):
        for name in files:
            filepath = os.path.join(root,name)
            absroot = os.path.abspath(root)
            if absroot == os.path.abspath("D:/home/r6_svn/Server/src/BtsDBSvr/mysql5.0/"):
                continue
            if absroot == os.path.abspath("D:/home/r6_svn/Server/src/InstallBGS/InstSDK/Include/"):
                continue

            if filepath.split('.')[-1:][0] == "cpp" or filepath.split('.')[-1:][0] == "h":
                # execute command
                cmd = "D:/home/r6_svn/Cygwin/bin/sed.exe -f cpp.script " + filepath + " > " + filepath + "_format"
                os.system(cmd)
                os.remove(filepath)
                os.rename(filepath + "_format", filepath)

                cmd = "D:/home/r6_svn/Cygwin/bin/sed.exe -f cpp_lines.script " + filepath + " > " + filepath + "_format"
                os.system(cmd)
                os.remove(filepath)
                os.rename(filepath + "_format", filepath)
                pass
            else:
                pass

if __name__ == "__main__":
    import sys
    import os
    #dirpath = sys.argv[0] + "/../../"
    #dirpath = "D:/text/text"
    #dirpath = "E:/home/r6_svn/Client/src/BGS/AcsStart"
    #dirpath = "D:/home/r6_svn/Doc/CodeFormat"
    #dirpath = "D:/home/r6_svn/Server/src/BtsServer"
    #dirpath = "D:/home/r6_svn/Client/src/BGS"
    #dirpath = "D:/home/r6_svn/BTSDA/src/BTSDA"
    #dirpath = "D:/home/r6_svn/BTSDA"
    dirpath = "D:/home/r6_svn/Server"
    #dirpath = "D:/home/r6_svn/Client/src/BGS/FControl"
    #dirpath = "D:/home/r6_svn/Client/src/BGS/MiddleMgr"
    #dirpath = "D:/home/r6_svn/Server/src/BtsDBSvr/mysql5.0"
    print(dirpath)

    walk_dir(dirpath, topdown = False)
